use Test;
use Rollout qw/file_append slurp_file/;
use strict;

BEGIN { plan tests => 11 }

unlink "/tmp/banana";
ok(!file_append("/tmp/banana", "line\n", qr/^line/));
ok(file_append("/tmp/banana", "line again\n", qr/line again/, -create=>1));
ok(slurp_file("/tmp/banana") eq "line again\n");
ok(file_append("/tmp/banana", <<EOTEXT, qr/line \d+/));
line 10
line 20
line 30
line 40
EOTEXT
ok(file_append("/tmp/banana", <<EOTEXT, qr/line [23]\d/));
line 20 yay!
line 30 yay!
EOTEXT
ok(file_append("/tmp/banana", <<EOTEXT, qr/./));
before
BEGIN foo
foo
bar
baz
END
after
EOTEXT
ok(file_append("/tmp/banana", <<EOTEXT, sub { /^BEGIN foo/../^END/ }));
BEGIN foo
1
END
EOTEXT
ok(!file_append("/tmp/banana", <<EOTEXT, sub { /^BEGIN foo/../^END/ }));
BEGIN foo
1
END
EOTEXT
ok(slurp_file("/tmp/banana") eq "before\nBEGIN foo\n1\nEND\nafter\n");
ok(file_append("/tmp/banana", "", -pat_from => qr/^BEGIN foo/, -pat_to => qr/^END/));
ok(slurp_file("/tmp/banana") eq "before\nafter\n");
